package com.framework.web.controller.module.user;

import com.framework.common.annotation.QueryTarget;
import com.framework.common.model.validation.ValidationGroup;
import com.framework.common.model.response.R;
import com.framework.common.util.other.NumeralUtil;
import com.framework.common.util.system.SystemUtil;
import com.framework.model.module.user.vo.UserVo;
import com.framework.service.module.user.UserService;
import com.framework.web.base.BaseController;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 龘鵺
 * @version 1.0
 * @className com.framework.web.controller.module.user.UserController
 * @description 用户请求控制类
 * @datetime 2024-06-20 20:28:00
 */
@Validated
@Controller
@RequestMapping("/module/user/user")
public class UserController extends BaseController {
    private String path = "lowerright/module/user/user/";
    @Autowired
    private UserService userServiceImpl;

    /**
     * @return org.springframework.web.servlet.ModelAndView
     * @title 分页页面跳转
     * @description 分页页面跳转
     * @author 龘鵺
     * @datetime 2024-06-20 20:28:00
     * @version 1.0
     */
    @GetMapping("/page/list")
    @PreAuthorize("hasPermission('" + SystemUtil.SYSTEM_MENU_NAME + "','USER_LIST_MANAGEMENT')")
    public ModelAndView pageList() {
        ModelAndView mv = new ModelAndView(path + "userList");
        return mv;
    }

    /**
     * @return org.springframework.web.servlet.ModelAndView
     * @title 新增页面跳转
     * @description 新增页面跳转
     * @author 龘鵺
     * @datetime 2024-06-20 20:28:00
     * @version 1.0
     */
    @GetMapping("/get/add")
    @PreAuthorize("hasPermission('" + SystemUtil.SYSTEM_BUTTON_NAME + "','USER_LIST_MANAGEMENT:add')")
    public ModelAndView getAdd() {
        ModelAndView mv = new ModelAndView(path + "userAdd");
        return mv;
    }

    /**
     * @param id 1 编号
     * @return org.springframework.web.servlet.ModelAndView
     * @title 编辑页面跳转
     * @description 编辑页面跳转
     * @author 龘鵺
     * @datetime 2024-06-20 20:28:00
     * @version 1.0
     */
    @GetMapping("/get/edit")
    @PreAuthorize("hasPermission('" + SystemUtil.SYSTEM_BUTTON_NAME + "','USER_LIST_MANAGEMENT:edit')")
    public ModelAndView getEdit(@NotNull(message = "请选择用户") @Min(value = NumeralUtil.POSITIVE_ONE, message = "用户不存在") Long id) {
        ModelAndView mv = new ModelAndView(path + "userEdit");
        mv.addObject("p", userServiceImpl.getByIdParam(id));
        return mv;
    }

    /**
     * @param id 1 编号
     * @return org.springframework.web.servlet.ModelAndView
     * @title 查看页面跳转
     * @description 查看页面跳转
     * @author 龘鵺
     * @datetime 2024-06-20 20:28:00
     * @version 1.0
     */
    @GetMapping("/get/view")
    @PreAuthorize("hasPermission('" + SystemUtil.SYSTEM_BUTTON_NAME + "','USER_LIST_MANAGEMENT:view')")
    public ModelAndView getView(@NotNull(message = "请选择用户") @Min(value = NumeralUtil.POSITIVE_ONE, message = "用户不存在") Long id) {
        ModelAndView mv = new ModelAndView(path + "userView");
        mv.addObject("p", userServiceImpl.getByIdParam(id));
        return mv;
    }

    /**
     * @param row 1 用户类
     * @return com.framework.common.model.response.R
     * @title 分页查询
     * @description 分页查询
     * @author 龘鵺
     * @datetime 2024-06-20 20:28:00
     * @version 1.0
     */
    //@Validated(value = {ValidationGroup.formQuery.class})
    @ResponseBody
    @QueryTarget
    @GetMapping("/find/page/list")
    @PreAuthorize("hasPermission('" + SystemUtil.SYSTEM_BUTTON_NAME + "','USER_LIST_MANAGEMENT:find_page_list')")
    public R<?> findPageList(@Validated(value = {ValidationGroup.formPageQuery.class}) UserVo row) {
        return userServiceImpl.findParamPageList(row);
    }

    /**
     * @param row 1 用户类
     * @return com.framework.common.model.response.R
     * @title 新增
     * @description 新增
     * @author 龘鵺
     * @datetime 2024-06-20 20:28:00
     * @version 1.0
     */
    @ResponseBody
    @PostMapping("/save")
    @PreAuthorize("hasPermission('" + SystemUtil.SYSTEM_BUTTON_NAME + "','USER_LIST_MANAGEMENT:add')")
    public R<?> save(@Validated(value = {ValidationGroup.formAdd.class}) UserVo row) {
        return userServiceImpl.save(row);
    }

    /**
     * @param id 1 编号
     * @return com.framework.common.model.response.R
     * @title 重置密码
     * @description 重置密码
     * @author 龘鵺
     * @datetime 2024-06-20 20:28:00
     */
    @GetMapping(value = "/reset/password", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    @PreAuthorize("hasPermission('" + SystemUtil.SYSTEM_BUTTON_NAME + "','SYSTEM_USER_LIST_MANAGEMENT:resetPassword')")
    public R<?> resetPassword(@NotNull(message = "请选择用户") @Min(value = NumeralUtil.POSITIVE_ONE, message = "用户不存在") @Max(value = Long.MAX_VALUE, message = "用户不存在") @RequestParam(value = "id") Long id) {
        return userServiceImpl.resetPassword(id);
    }

    /**
     * @param id 1 编号
     * @return com.framework.common.model.response.R
     * @title 启用禁用
     * @description 启用禁用
     * @author 龘鵺
     * @datetime 2024-06-20 20:28:00
     */
    @GetMapping(value = "/enable", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    @PreAuthorize("hasPermission('" + SystemUtil.SYSTEM_BUTTON_NAME + "','SYSTEM_USER_LIST_MANAGEMENT:enable')")
    public R<?> enable(@NotNull(message = "请选择用户") @Min(value = NumeralUtil.POSITIVE_ONE, message = "用户不存在") @Max(value = Long.MAX_VALUE, message = "用户不存在") @RequestParam(value = "id") Long id) {
        return userServiceImpl.enable(id);
    }

//    /**
//     * @param row 1 用户类
//     * @return com.framework.common.model.response.R
//     * @title 编辑
//     * @description 编辑
//     * @author 龘鵺
//     * @datetime 2024-06-20 20:28:00
//     * @version 1.0
//     */
//    @ResponseBody
//    @PostMapping("/edit")
//    @PreAuthorize("hasPermission('" + SystemUtil.SYSTEM_BUTTON_NAME + "','USER_LIST_MANAGEMENT:edit')")
//    public R<?> edit(@Validated(value = {ValidationGroup.formEdit.class}) UserVo row) {
//        return userServiceImpl.edit(row);
//    }
//
//    /**
//     * @param idList 1 编号集合
//     * @return com.framework.common.model.response.R
//     * @title 批量删除
//     * @description 批量删除
//     * @author 龘鵺
//     * @datetime 2024-06-20 20:28:00
//     * @version 1.0
//     */
//    @ResponseBody
//    @PostMapping("/batch/del")
//    @PreAuthorize("hasPermission('" + SystemUtil.SYSTEM_BUTTON_NAME + "','USER_LIST_MANAGEMENT:batchDel')")
//    public R<?> batchDel(@NotEmpty(message = "请选择用户") @Size(min = NumeralUtil.POSITIVE_ONE, message = "用户不存在") @RequestParam(value = "idList[]") List<Long> idList) {
//        return userServiceImpl.batchDeleteList(idList);
//    }

    /**
     * @param id 1 编号
     * @return com.framework.common.model.response.R
     * @title 删除
     * @description 删除
     * @author 龘鵺
     * @datetime 2024-06-20 20:28:00
     * @version 1.0
     */
    @ResponseBody
    @DeleteMapping("/del")
    @PreAuthorize("hasPermission('" + SystemUtil.SYSTEM_BUTTON_NAME + "','USER_LIST_MANAGEMENT:del')")
    public R<?> del(@NotNull(message = "请选择用户") @Min(value = NumeralUtil.POSITIVE_ONE, message = "用户不存在") @Max(value = Long.MAX_VALUE, message = "用户不存在") @RequestParam(value = "id") Long id) {
        return userServiceImpl.delete(id);
    }
}